<template>
  <div>
    <el-form :inline="true" ref="form" :model="form" label-width="80px">
      <el-form-item label="角色名称">
        <el-input v-model="form.roleName"></el-input>
      </el-form-item>
      <el-form-item label="权限字符">
        <el-input v-model="form.roleKey"></el-input>
      </el-form-item>
      <el-form-item label="角色状态">
        <el-select v-model="form.status" placeholder="用户状态">
          <el-option label="正常" value="0"></el-option>
          <el-option label="停用" value="1"></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="创建时间">
        <el-date-picker
            v-model="createTime"
            value-format="yyyy-MM-dd HH:mm:ss"
            format="yyyy-MM-dd HH:mm:ss"
            type="datetimerange"
            :default-time="['00:00:00', '23:59:59']"
            range-separator="至"
            start-placeholder="开始日期"
            end-placeholder="结束日期">
        </el-date-picker>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" @click="rolesList">查询</el-button>
        <el-button>取消</el-button>
      </el-form-item>
    </el-form>
    <el-row>
      <el-button type="primary" @click="toAdd">添加</el-button>
      <el-button type="success" @click="selectUser">修改</el-button>
      <el-button type="danger" @click="deleteUser">删除</el-button>
      <el-button type="info">导入</el-button>
      <el-button type="warning" @click="exportUsers">导出</el-button>
    </el-row>
    <el-table
        ref="multipleTable"
        :data="tableData"
        tooltip-effect="dark"
        style="width: 100%"
        @selection-change="handleSelectionChange">
      <el-table-column
          type="selection" width="55">
      </el-table-column>
      <el-table-column
          label="角色编号"
          prop="roleId"
          width="120">
      </el-table-column>
      <el-table-column
          prop="roleName"
          label="角色名称"
          width="120">
      </el-table-column>
      <el-table-column
          prop="roleKey"
          label="权限字符"
          show-overflow-tooltip>
      </el-table-column>
      <el-table-column
          prop="roleSort"
          label="显示顺序"
          show-overflow-tooltip>
      </el-table-column>
      <el-table-column
          label="状态"
          show-overflow-tooltip>
        <template scope="ss">
          <el-switch
              v-model="ss.row.status"
              active-value="0"
              inactive-value="1"
              @change="updateRoleStatus(ss.row.status,ss.row.roleId)">
          </el-switch>
        </template>
      </el-table-column>
      <el-table-column
          prop="createTime"
          label="创建时间"
          show-overflow-tooltip>
      </el-table-column>
      <el-table-column
          label="操作"
          show-overflow-tooltip>
      </el-table-column>
    </el-table>
    <div style="margin-top: 20px">
      <el-pagination
          @size-change="handleSizeChange"
          @current-change="handleCurrentChange"
          :page-sizes="[1, 2, 3, 4,5,6]"
          :page-size=pageSize
          layout="total, sizes, prev, pager, next, jumper"
          :total=total>
      </el-pagination>
    </div>
  </div>
</template>

<script>
  export default {
    data(){
      return {
        createTime:[],
        pageNum:1,
        pageSize:3,
        total:0,
        form: {
          roleName: '',
          roleKey:'',
          status: '',
          createStartTime:'',
          createEndTime:''
        },
        tableData: []
      }
    },
    methods: {
      rolesList(){
        const params= this.form;
        params.createStartTime=this.createTime[0];
        params.createEndTime=this.createTime[1];
        params.pageNum=this.pageNum;
        params.pageSize = this.pageSize;
        this.axios.get("http://localhost:6785/roles/select",{params}).then(res=>{
          console.log(res.data.list.list);
          this.tableData=res.data.list.list;
          this.total = res.data.list.total;
          this.pageNum=res.data.list.pageNum;
          this.pageSize=res.data.list.pageSize;
        })
        console.log(params)
      },
      //每页多少条数据
      handleSizeChange(val) {
        this.pageSize=val;
        this.rolesList();
      },
      //查询第几页数据
      handleCurrentChange(val) {
        this.pageNum = val;
        this.rolesList();
      }
    },
    created() {
      this.rolesList();
    }
  }
</script>


<style scoped>
</style>
